/*
RAWR-Template - JS

 (c) 2007-2009, RAWR Designs, Some Rights Reserved -
	Christopher "That Stevens Guy" Stevens
	Richard "Giant Eagle" Tuininga
 (CC) http://creativecommons.org/licenses/by-nc-sa/3.0

 Any queries? -
	Email: contact[at]rawr-designs.com
	Forum: http://www.rawr-designs.com/forum/
 	Homepage: http://www.rawr-designs.com
*/
// Pageload
var statsOff = autoplay = false;
var playList = new Array();
function pageLoad() {
// Set module state according to cookie.
	if(getCookie("Shoutbox")=="pinned")		hideShow("Shoutbox");
	if(getCookie("Statistics")=="pinned")	hideShow("Statistics");
	if(getCookie("Folder_Tasks")=="pinned") hideShow("Folder_Tasks");
	if(getCookie("moduleCol")=="pinned")	hideShow("moduleCol");
// Autoplay a media file.
	if(document.location.href.indexOf("?playMedia=")!=-1) {
		autoplay = true;
		file = document.location.href.split("?playMedia=");
		setTimeout("initBox(\"specialBox\",\""+file[0]+file[1]+"\");",500);
	}
// Create dynamic playlist.
	ele = document.getElementsByTagName("div");
	for(i=0,j=0;i<ele.length;i++) {
		if(ele[i]) if(ele[i].getAttribute("name")) if(ele[i].getAttribute("name") == "mediaFile") {
			playList[j] = ele[i];
			playList[j].name = ele[i].firstChild.name;
			playList[j].boxid = ele[i].parentNode.childNodes[1].id;
			j++;
		}
	}
// Execute updating statistics.
	if(mod_statistics=="on")ahah("/~stats.htm?",Math.random(),"stats");
}
// RAWR document.getElementById
function gEBI(a,b,c) {
	if(!b&&!c)return document.getElementById(a);
	if(b=="inn")if(c)gEBI(a).innerHTML=c; else return gEBI(a).innerHTML;
	if(b=="add"&&c)gEBI(a).innerHTML+=c;
}
// Cookie Code
var exp = new Date();
exp.setTime(exp.getTime()+(1000*60*60*24*7));//Set timeout to 7 days
function setCookie(name,val,expires) {
	document.cookie=name+"="+escape(val)+"; path=/"+((expires == null)?"":"; expires="+expires.toGMTString());
}
function getCookie(name) {
	cname=name+"="; 
	dc=document.cookie;
	if(dc.length>0) {
		begin=dc.indexOf(cname); 
		if(begin!=-1) { 
			begin+=cname.length; 
			end=dc.indexOf(";",begin);
			if(end==-1)end=dc.length;
			return unescape(dc.substring(begin,end));
		} 
	}
	return null;
}
// Pin Module
function pinModule(mod) {
	cookie = getCookie(mod)?getCookie(mod):"normal";
	if (cookie=="normal") setCookie(mod,"pinned",exp);
	else setCookie(mod,"normal",exp);
	hideShow(mod);
}
// Module Hide/Show
var oppVar;
function hideShow(mod) {
	try {
		hs=gEBI(mod);
		hsLnk=gEBI(mod+"_Link");
		if(hs.style.display=="none") {
			mod=="moduleCol"?oppVar="show":oppVar="hide";
			hs.style.display="block";
			hsLnk.firstChild.src="/template/"+theme+"/images/"+oppVar+".gif";
			hsLnk.title=lv_hideTitle;
			if(mod=="Statistics")statsOff = false;
		} else {
			mod=="moduleCol"?oppVar="hide":oppVar="show";
			hs.style.display="none";
			hsLnk.firstChild.src="/template/"+theme+"/images/"+oppVar+".gif"
			hsLnk.title=lv_showTitle;
			if(mod=="Statistics")statsOff = true;
		}
	} catch (e) {}
}
// Update Statistics
function ahah(url,r,t) {
	window.XMLHttpRequest?req=new XMLHttpRequest():req=new ActiveXObject("Microsoft.XMLHTTP");
	if(req != undefined && statsOff == false) {
		req.onreadystatechange=function(){ahahDone(url,t);}
		req.open("GET",url+r,true);
		req.send("");
	} else {
		setTimeout("ahah(\""+url+"\",Math.random(),\""+t+"\")",10000);
	}
} 
function ahahDone(url,t) {
	if(req.readyState == 4 && req.status == 200) {
		if(statsOff == false)gEBI(t,'inn',req.responseText);
		setTimeout("ahah(\""+url+"\",Math.random(),\""+t+"\")",10000);
	}
}
// Add Upload Inputs
var f=0;
function addInput() {
	f++;
	fr=document.upfrm;
	mr=fr.more;
	document.getElementById('f'+f).style.display='block';
	if(f>=9)mr.disabled='disabled'; 
}
function disableBtns() {
	fr=document.upfrm;
	fr.upbtn.disabled=fr.more.disabled='disabled';
}
// RAWR Search
function searchQuery() {
	frm = document.searchForm;
	if(frm.query.value.length < 3) {
		alert(lv_searchAlert);
	} else {
		frm.recursive.checked ?	recursive ="&recursive" : recursive ="";
		for(x=0; x<frm.choice.length; x++) {
			if(frm.choice[x].checked ==1) {
				if(frm.choice[x].value =="file") {
					searchMode ="?files-filter=";
					filter="&folders-filter=%5C";
				} else if(frm.choice[x].value =="folder") {
					searchMode ="?folders-filter=";
					filter="&files-filter=%5C";
				} else {
					searchMode ="?filter=";
					filter="";
				}
			}
		}
		for(c=0; c<frm.root.length; c++) {
			if(frm.root[c].checked ==1) {
				frm.root[c].value =="current" ?	searchFrom ="http://"+serverHost+serverFolder : searchFrom ="http://"+serverHost;
			}
		}
		document.location.href = searchFrom+searchMode+"*"+frm.query.value+"*"+recursive+filter;
	}
}